using Glue;
using Glue.Internals;
using GlueTests.Builders;
using Xunit;

namespace GlueTests.ConverterContainerTests
{
    public class When_no_converters_are_added
    {
        private readonly ConverterContainer converters;
        private readonly IObjectMember nullableBooleanProperty;
        private readonly IObjectMember booleanProperty;
        private readonly IObjectMember doubleProperty;

        public When_no_converters_are_added()
        {
            converters = new ConverterContainer();
            nullableBooleanProperty = PropertyBuilder.AsNullableBooleanProperty().Build();
            booleanProperty = PropertyBuilder.AsBooleanProperty().Build();
            doubleProperty = PropertyBuilder.AsDoubleProperty().Build();
        }

        [Fact]
        public void Should_be_able_to_convert_same_types()
        {
            Assert.True(converters.CanConvert(doubleProperty, doubleProperty));
            Assert.NotNull(converters.Get(doubleProperty, doubleProperty, RelationDirection.TwoWays));
        }

        [Fact]
        public void Should_get_an_exception_when_asking_for_different_types()
        {
            Assert.Throws(typeof(GlueException), () => converters.Get(booleanProperty, doubleProperty, RelationDirection.TwoWays));
        }

        [Fact]
        public void Should_by_default_AcceptNullablesAsNormalTypes()
        {
            Assert.True(converters.CanConvert(nullableBooleanProperty, booleanProperty));
            Assert.True(converters.CanConvert(booleanProperty, nullableBooleanProperty));
        }

        [Fact]
        public void Should_by_default_return_converter_for_AcceptNullablesAsNormalTypes()
        {
            Assert.NotNull(converters.Get(nullableBooleanProperty, booleanProperty,RelationDirection.TwoWays));
            Assert.NotNull(converters.Get(booleanProperty, nullableBooleanProperty, RelationDirection.TwoWays));
        }
    }
}
